package com.mars.rabbitmq.delayPlugins;

import com.google.common.collect.Maps;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Map;

/**
 * @Author King
 * @create 2020/8/19 10:32
 */
@Data
@Slf4j
@Configuration
public class DelayPluginsRabbitMqConfig {

    public static final String DELAY_EXCHANGE = "delayPluginsOrderExchange";
    public static final String DELAY_QUEUE = "delayPluginsOrderQueue";
    public static final String DELAY_ROUTING_KEY = "delayPluginsOrderRoutingKey";


    @Bean
    public CustomExchange delayPluginsOrderExchange() {
        Map<String, Object> args = Maps.newHashMap();
        args.put("x-delayed-type", "direct");
        return new CustomExchange(DELAY_EXCHANGE, "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue delayPluginsOrderQueue() {
        return new Queue(DELAY_QUEUE, true);
    }

    @Bean
    public Binding delayPluginsOrderBinding() {
        return BindingBuilder.bind(delayPluginsOrderQueue()).to(delayPluginsOrderExchange()).with(DELAY_ROUTING_KEY).noargs();
    }

}
